<?php require ("../header.php"); ?>

<style type="text/css">
<!--
.style1 {color: #FF0000}
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style>

<?php
	include ("../../engine/sql.inc.php");
	include ("../../config/conn.php");
	if($ad_check<=0){
	header ("Location:../login.php?action=0");
	}
?>

<?php
	//gather from question_reg_next.php form.  GET data from previous form.
	if (isset($_GET['subject'])) {
		$sub=$_GET['subject'];
		$sub=clean($subject);
	}
	if (isset($_GET['dep'])) {
		$dep=$_GET['dep'];
		$dep=clean($q_department);
	}
	if (isset($_GET['course'])) {
		$course=$_GET['course'];
		$course=clean($course);
	}
	if (isset($_GET['sem'])) {
		$sem=$_GET['sem'];
		$sem=clean($sem);
	}
	if (isset($_GET['class'])) {
		$class=$_GET['class'];
		$class=clean($class);
	}
	if (isset($_GET['quiz'])) {
		$quiz=$_GET['quiz'];
		$quiz=clean($quiz);
	}

	
	//gather data for question table	
	if (isset($_POST['sub'])){
		$sub		=	$_POST['sub'];
		$dep		= 	$_POST['dep'];
		$sem		=	$_POST['sem'];
		$course		=	$_POST['course'];
		$class		=	$_POST['class'];
		$quiz		=	$_POST['quiz'];
	}
		
	$q_question		=	$_POST['question'];
	
	//gather data for answer table
	$answer[1]	=	$_POST['answer1'];
	$answer[2]	=	$_POST['answer2'];
	$answer[3]	=	$_POST['answer3'];
	$answer[4]	=	$_POST['answer4'];
	
	$point[1]	=	1;
	$point[2]	=	0;
	$point[3]	=	0;
	$point[4]	=	0;
	
	//Operasi memasukkan data Soalan ke dalam database -> question
	$sql_insert_question	=	"INSERT INTO quiz_question (id,ad_id,quiz_subject,quiz_department,quiz_sem,quiz_course,quiz_class,quiz_number,quiz_question) 
								VALUES (NULL,'$id','$sub','$dep','$sem','$course','$class','$quiz','$q_question')";
	$insert_question		=	mysql_query($sql_insert_question);
	$ans_id					=	mysql_insert_id();
	
	//Operasi memasukkan jawapan ke dalam set database -> answer
	$count = 1;
	while ($count<5)
	{
		$sql_insert_ans	=	"INSERT INTO quiz_answer (ques_id,answer,point)
							VALUES ('$ans_id','$answer[$count]','$point[$count]')";
		$insert_ans		=	mysql_query($sql_insert_ans);
		$count++;
	}
	$sql_check_data="SELECT a.id,b.ques_id FROM quiz_question a,quiz_answer b WHERE a.id='$ans_id' AND b.ques_id='$ans_id'";
	$call_check_data=mysql_query($sql_check_data);
	$check_count=mysql_num_rows($call_check_data);
	
	if ($check_count>0)
	{ ?>
		<div align="center">
 	 	<p>&nbsp;</p>
 	 	<p>&nbsp;</p>
 	 	<p>&nbsp;</p>
 	 	<table width="780" border="1" bordercolor="#999999" bgcolor="#999999">
    		<tr>
      		<td bgcolor="#000000"><div align="center" class="style1">
       		  <p>&nbsp;</p>
        		<p>Question succesfully registered and stored into database </p>
       		 <p>&nbsp;</p>
    		  </div></td>
 	  		 </tr>
 		 </table>
 		 <p>&nbsp;</p>
 		 <table width="488" border="0">
           <tr>
             <td width="240"><div align="left"><?php echo "<a href = \"../question_reg.php\">" ?>Register Question For New Quiz </div></td>
             <td width="238"><div align="right">
			 <?php echo "<a href = \"../quiz_reg_next.php?sub=".$sub."&&dep=".$dep."&&sem=".$sem."&&course=".$course."&&quiz=".$quiz."&&class=".$class."\">
			 Register Question For Same Quiz </a>"; ?></div></td>
           </tr>
         </table>
 		 <p>&nbsp;</p>
 		 <p>&nbsp;</p>
 		 <p>&nbsp;</p>
		</div>
	<?php } ?>
	
<?php require ("../footer.php"); ?>
